package com.longchat.controller.admin.system;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.longchat.controller.admin.BaseController;
import com.longchat.domain.permission.SysUser;
import com.longchat.dto.comm.DatatablesPageViewInfo;
import com.longchat.dto.system.SysUserQueryInfo;
import com.longchat.interceptor.Permission;
import com.longchat.service.impl.system.SysUserService;


@Controller
@RequestMapping("/admin/system")
public class SystemController extends BaseController{
	private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(SystemController.class);
	@Autowired
	private SysUserService sysUserService;
	
	@Permission(validate=false)
	@ResponseBody
	@RequestMapping("/user/list")
	public DatatablesPageViewInfo<SysUser> querySysUsersList(SysUserQueryInfo info,HttpSession session){
		try{
			
			return sysUserService.queryPageBy(info);
		}catch(Exception ex){
			logger.error("查询用户信息错误",ex);
		}
		return new DatatablesPageViewInfo<SysUser>().nullPages();
	}
	@Permission(validate=false)
	@RequestMapping("/users")
	public String userList(){
		logger.debug("users list查询。。。。。。。。");
		return "/admin/system/users";
	}
	/*@ResponseBody
	@RequestMapping("/users/add")
	public ResultInfo addSysUser(UserMaintainInfo info){
		try{
			return userService.addUser(info);
		}catch(Exception ex){
			log.error("增加系统用户信息错误",ex);
		}
		return ResultInfo.FAILD;
	}
	@Permission(validate=false)
	@RequestMapping("toAddSysUser")
	public String toAddSysUser(HttpServletRequest req,HttpSession session){
		SysUserInfo user = getUserInfo(session);
		if(user==null){
			throw new RuntimeException("没有登录");
		}
		List<TypeInfo> roles = roleService.queryUserRole(user.isCustomer(),user.getUserName());
		req.setAttribute("roles", roles);
		 if(StringUtil.isNotNil(brandList)){
		   req.setAttribute("brands",Arrays.asList(brandList.split(",")));
		 }
		 return "settings/userinfo_dialog";
	}
	@Permission(validate=false)
	@RequestMapping("toModifySysUser")
	public String toModifySysUser(String id,HttpServletRequest req,HttpSession session){
		SysUserInfo user = getUserInfo(session);
		if(user==null){
			throw new RuntimeException("没有登录");
		}
		List<TypeInfo> roles = roleService.queryUserRole(user.isCustomer(),user.getUserName());
		req.setAttribute("roles", roles);
		if(StringUtil.isNotNil(brandList)){
			req.setAttribute("brands",Arrays.asList(brandList.split(",")));
		}
		SystemUserInfo sysUser = userService.queryUser(id);
		req.setAttribute("sysUser", sysUser);
		return "settings/userinfo_dialog";
	}
	
	@ResponseBody
	@RequestMapping("updateSysUser")
	public ResultInfo updateSysUser(UserMaintainInfo info){
		try{
			return userService.updateUser(info);
		}catch(Exception ex){
			log.error("修改系统用户信息错误",ex);
		}
		return ResultInfo.FAILD;
	}
	@ResponseBody
	@RequestMapping("updateSysUserStatus")
	public ResultInfo updateSysUserStatus(String id,String status){
		try{
			return userService.updateUserStatus(id,status);
		}catch(Exception ex){
			log.error("修改系统用户信息状态错误",ex);
		}
		return ResultInfo.FAILD;
	}
	@ResponseBody
	@RequestMapping("updatePwd")
	public ResultInfo updatePwd(PasswordUpdateInfo info,HttpSession session){
		try{
			info.setId(getUserInfo(session).getId());
			return userService.updatePassword(info);
		}catch(Exception ex){
			log.error("修改密码错误",ex);
		}
		return new ResultInfo(ResultInfo.FAILDCODE,"修改密码错误");
	}
	//系统用户增删改查 end
*/}
